package com.rth.wx.Handler;

import com.rth.wx.enums.WechatMsgTypeEnum;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SubscribeTextHandler implements WechatMsgHandler {
    @Override
    public WechatMsgTypeEnum getMsgType() {
        return WechatMsgTypeEnum.SUBSCRIBE;
    }

    @Override
    public String handlerByMsgType(Map<String, String> msgMap) {

        String toUserName = msgMap.get("ToUserName");
        String fromUserName = msgMap.get("FromUserName");
        String subscribeMsg = "感谢你的关注,我是理塘丁真！";

        String content = "<xml>\n" +
                "  <ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>\n" +
                "  <FromUserName><![CDATA[" + toUserName + "]]></FromUserName>\n" +
                "  <CreateTime>12345678</CreateTime>\n" +
                "  <MsgType><![CDATA[text]]></MsgType>\n" +
                "  <Content><![CDATA[" + subscribeMsg + "]]></Content>\n" +
                "</xml>";

        return content;
    }
}
